[#ftl]
[@define "agile.dijit._PopupSubMenuMixin"]
	init:function(){
		if(this._initPopupSubMenuMixin) return; this._initPopupSubMenuMixin=true;
		
		this._subMenu = null;
		query(">.agileMenu",this.containerNode).forEach(function(node){
			this._subMenu = registry.byNode(node);
			this._subMenu.parent = this;
			this._subMenu.metadata("isSubMenu",true);
			this.metadata("parameters.isSubMenu",true);
			style.set(this._subMenu.domNode,{display:"none"});			
			lang.mixin(this._subMenu,{onDeselected:function(event){},onSelected:function(event){}});				
		},this);		
	}
	,showSubMenu:function(visible){

		if(!this._subMenu){
			this._subMenu = new agile.dijit.Menu({isSubMenu:true,moveable:false});
			this._subMenu.placeAt(this.containerNode,"first");
			this._subMenu.metadata("isSubMenu",true);
			this._subMenu.metadata("moveable",false);
			this._subMenu.parent = this;
			this._subMenu.startup();	
			lang.mixin(this._subMenu,{onDeselected:function(event){},onSelected:function(event){}});	
			this._subMenu.computeSize();
		}
		
		if(!visible){
			style.set(this._subMenu.domNode,{display:"none"});
		}else{	
			var left = 0;
			var top = 0;
			
			switch(this.getPopupMenuPositon()){
				case "above": 
					top = 0 - this.dimension.height - 2;
					break;
				case "below":
					top = this.dimension.height + 2; 
					break;
				case "left": 
					left = 0 - this.dimension.left - this.dimension.width - 2;
					break;
				case "right": 
					//left = this.parent.dimension.width + this.dimension.left + 2;
					left = this.dimension.width + this.dimension.left + 2;
					break;				
			}

			style.set(this._subMenu.domNode,{display:"block",left: left+"px",top: top+"px"});
		}
	}
	,getPopupMenuPositon:function(){
		return "below";//left,right,above
	}
	//remove the sub menu
	,removeChild:function(child){
		construct.destroy(this._subMenu.domNode);
		this._subMenu = null;
//		this._subMenuVisible = false;
		this.metadata("parameters.isSubMenu",false);
		
		if(this.arrowWrapper){
			style.set(this.arrowWrapper,{visibility:"hidden"});
		}
	}
	,getTemplateParameters:function(params){
		var parameters = this.inherited(arguments);
		
		if(this._subMenu && this._subMenu.hasChildren()){
			parameters.widgetName = "Popup"+this.metadata("widgetName");
			
			parameters.dojoDeclaredClass= lang.replace("dijit/Popup{widgetName}",{widgetName:this.widgetName});
		}
		
		return parameters;
	}
	,getInnerWidgetTemplate:function(params){
		var template = "";		
		if(this._subMenu && this._subMenu.hasChildren()){
		     template = this._subMenu.toHtml(params);
		}
		return template;
	}
[/@]